const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
       canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
     },
 bindGetUserInfo: function (e) {
          var encryptedData = e.detail.encryptedData
          var iv = e.detail.iv
          if (!encryptedData) {
               return
          }
          this.loinByWx(encryptedData, iv)
     },
loinByWx: function (encryptedData, iv) {
     wx.login({
          success: res => {
               var data = { 'code': res.code, 'memberId': app.globalData.userInfo.id, 'encryptedData': encryptedData,'iv':iv}
               var promise = app.synPostData('member/loginWithUnion', data)
                    promise.then(function (res) {
                         if (res.data.code != 0) {
                              wx.showToast({
                                   title: '登录失败',
                                   icon: 'none',
                                   duration: 1500
                              })
                         } else {
                              app.globalData.userInfo = res.data.result
                              wx.switchTab({
                                   url: '../index/index'
                              })
                         }
                    }); 
               }
          })
     }
})